package com.leonne.harpacristabrasileira.activities;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import com.leonne.harpacristabrasileira.R;
import com.leonne.harpacristabrasileira.singleton.CustomMediaPlayer;
import com.leonne.harpacristabrasileira.tools.MyConstants;

public class GenericActivity extends Activity{

	protected CustomMediaPlayer generalMediaPlayer;
	protected int internetError;
	protected int idAnthem;
	
	protected void initiateGeneralMediaPlayer(){
		if (this.generalMediaPlayer == null)
			this.generalMediaPlayer = CustomMediaPlayer.getInstance();
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.default_menu, menu);
	    return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		Intent intent;
	    switch (item.getItemId()) {
	        case R.id.itemMenuIndex:     
	        	intent = new Intent(GenericActivity.this, FirstPageActivity.class);
	        	intent.putExtra("FORCESEARCH", MyConstants.ISFAVORITE);
	    		MyConstants.ISFAVORITE = false;
	    		startActivity(intent);
	    		overridePendingTransition(R.anim.push_down_in, R.anim.push_down_out);
	            break;
	        case R.id.itemMenuFavorites:
	        	intent = new Intent(GenericActivity.this, FirstPageActivity.class);
	        	MyConstants.ISFAVORITE = true;
	        	intent.putExtra("FORCESEARCH", true);
	    		startActivity(intent);
	    		overridePendingTransition(R.anim.push_down_in, R.anim.push_down_out);
	            break;
	        case R.id.itemMenuSettings:
	        	intent = new Intent(GenericActivity.this, ConfigurationsActivity.class);
	        	intent.putExtra("IDANTHEM", idAnthem);
	    		startActivity(intent);
	    		overridePendingTransition(R.anim.rotate3d_in_right_to_left, R.anim.rotate3d_out_right_to_left);
	            break;
	        case R.id.itemMenuHelp:
	        	intent = new Intent(GenericActivity.this, HelpActivity.class);
	        	intent.putExtra("IDANTHEM", idAnthem);
	        	startActivity(intent);
	        	overridePendingTransition(R.anim.push_down_in, R.anim.push_down_out);
	        	break;
	        case R.id.itemMenuAbout:
	        	intent = new Intent(GenericActivity.this, AboutActivity.class);
	        	intent.putExtra("IDANTHEM", idAnthem);
	        	startActivity(intent);
	        	overridePendingTransition(R.anim.push_down_in, R.anim.push_down_out);
	        	break;
	    }
	    return true;
	}
	
	protected void raiseInternetError() {
		try{
			String errorMessage = "";
			if (this.internetError == 0)
				return;
			else if (this.internetError == 1)
				errorMessage = getString(R.string.withoutInternetError).toString();
			else if (this.internetError == 2)
				errorMessage = getString(R.string.webServerOffLineError).toString();
				new AlertDialog.Builder(GenericActivity.this)
								.setIcon(R.drawable.warning)
								.setTitle(R.string.internetErrorTitle)
								.setMessage(errorMessage)
								.setNeutralButton("Ok", null)
								.show();
			return ;
		} catch (Exception e) {
			return;
		}
	}
	
}
